const router = require("express").Router();
const mysql = require("./../mysql");
const User = require("./../mysql/collection/User");
const Product = require("./../mysql/collection/Product");
/**
 * @swagger
 * /admin/statistic/user:
 *   get:
 *     summary: 用户总数统计
 *     tags: [管理端]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 用户总数统计成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: string
 *                   example: '200'
 *                 message:
 *                   type: string
 *                   example: '用户总数统计'
 *                 data:
 *                   type: integer
 *                   description: 用户总数
 */
router.get("/user", (req, res, next) => {
  mysql.find(User, {}, { _id: 0, __v: 0, password: 0 }).then((data) => {
    res.send({
      code: "200",
      message: "用户总数统计",
      data: data.length,
    });
  });
});
/**
 * @swagger
 * /admin/statistic/product:
 *   get:
 *     summary: 商品总数统计
 *     tags: [管理端]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 商品总数统计成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: string
 *                   example: '200'
 *                 message:
 *                   type: string
 *                   example: '商品总数统计'
 *                 data:
 *                   type: integer
 *                   description: 商品总数
 */
router.get("/product", (req, res, next) => {
  mysql.find(Product, {}, { _id: 0, __v: 0 }).then((data) => {
    res.send({
      code: "200",
      message: "商品总数统计",
      data: data.length,
    });
  });
});

module.exports = router;

